<?php
	/**
	 * Gmail class
	 * @author anton
	 *
	 */
	class Gmail
	{
	    /**
	     * Sends the gmail message
	     */
	    public static function Send(array $message)
	    {
	        require_once(CLASSES . SEPARATOR . "mail/class.phpmailer.php");
            $mail = new PHPMailer();
            
            $mailNumber = rand(1, 5);
            
            //server settings
            $mail->IsSMTP();
            $mail->SMTPAuth = true; // enable SMTP authentication
            $mail->SMTPSecure = "tls"; // sets the prefix to the server
            $mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
            $mail->Port = 587; // set the SMTP port for the GMAIL server            
            $mail->Username = "frommarkedd@gmail.com"; // SMTP username
            $mail->Password = "markedd7"; // SMTP password
            
            //sender
            $message['from'] = empty($message['from']) ? $mail->Username : $message['from'];
            $mail->From = $message['from'];
            $mail->FromName = $message['fromName'];
            $mail->AddReplyTo($message['from'], $message['fromName']);

            //recipients
            foreach ($message['recipients'] as $recipient)
            {
                $mail->AddAddress($recipient, $recipient);
            }
            
            $mail->IsHTML(true);
            $mail->Subject = $message['subject'];
            $mail->Body = $message['text'];
            $mail->CharSet = 'utf-8';
            
            //sends the message 
            if ($mail->Send())
            {
                return true;
            }
            else
            {
            	return $mail->ErrorInfo;
            }	        
	    }
	
	    /**
	     * Gets the mail content from file with parameters
	     * @param string $filename
	     * @param array $arguments
	     */
	    public static function GetContentFromFile($filename, array $arguments = array())
	    {        
	        return File::ParseTemplate(LANGUAGES.SEPARATOR.$_SESSION['lang'].SEPARATOR.'mail'.SEPARATOR.$filename.'.html', $arguments);
	    }
	}    
?>